
import { getSearchHot, getSearchHotDetail, searchSuggest } from '../../api/services/api'
export default ({
    namespaced: true,
    state: {
        hotSearchList: [],
        isSearch: false,
        searchInput: '陈奕迅',
        searchSug: {
            songs: [],
            artists: [],
            albums: [],
            playlists: [],
        }
    },
    mutations: {

        changeHotSearchList(state, val) {
            state.hotSearchList = [...val];
        },
        //改变搜索关键词
        changeSearchInput(state, val) {
            state.searchInput = val;
        },
        // 改变现实搜索关键词还是推荐关键词
        changeIsSearch(state, val) {
            state.isSearch = true;
        },
        //当用户删除掉所有的搜索信息清除搜索
        changeIsSearch2(state, val) {
            state.isSearch = false;
            state.searchInput = '';
            state.searchSug.playlists = [];
            state.searchSug.artists = [];
            state.searchSug.albums = [];
            state.searchSug.songs = [];


        },
        //改变搜索建议
        changSearchSug(state, val) {
            // state.searchSug.songs = val.songs;
            // state.searchSug.artists = val.artists;
            // state.searchSug.albums = val.albums;
            // state.searchSug.playlists = val.playlists;
            state.searchSug = { ...state.searchSug, ...val };
        }
    },
    actions: {
        async getSearchHot(context, val) {
            const data = await getSearchHot();
            // console.log('热搜', data);
            context.commit('changeHotSearchList', data.result.hots);
        },
        async getSearchHotDetail() {
            const data = await getSearchHotDetail()
            // console.log('热搜详情', data);
        },
        async searchSuggest(context, val) {
            const data = await searchSuggest(context.state.searchInput);
            console.log('搜索建议', data);
            context.commit('changSearchSug', data.result);
        }
    },

})
